<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="bus" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{busHome.managed ? 'Edit' : 'Add'} Bus</f:facet>


            <s:decorate id="idField" template="layout/edit.xhtml">
                <ui:define name="label">Id</ui:define>
                <h:inputText id="id"
                       required="true"
                       disabled="#{busHome.managed}"
                          value="#{busHome.instance.id}">
                    <a:support event="onblur" reRender="idField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>




            <s:decorate id="nameField" template="layout/edit.xhtml">
                <ui:define name="label">Name</ui:define>
                <h:inputText id="name"
                           size="20"
                      maxlength="20"
                          value="#{busHome.instance.name}">
                    <a:support event="onblur" reRender="nameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{busHome.persist}"
                       disabled="#{!busHome.wired}"
                       rendered="#{!busHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{busHome.update}"
                       rendered="#{busHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{busHome.remove}"
                      immediate="true"
                       rendered="#{busHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Bus.xhtml"
                rendered="#{busHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty busFrom ? 'BusList' : busFrom}.xhtml"
                rendered="#{!busHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Flight">
    <div class="association" id="flightParent">

        <h:outputText value="There is no flight associated with this bus."
                   rendered="#{busHome.instance.flight == null}"/>

        <rich:dataTable var="_flight"
                   value="#{busHome.instance.flight}"
                rendered="#{busHome.instance.flight != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="flightTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_flight.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Name</f:facet>
                <h:outputText value="#{_flight.name}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{busHome.instance.flight != null ? 'changeParent' : 'selectParent'}" value="#{busHome.instance.flight != null ? 'Change' : 'Select'} flight"
                       view="/FlightList.xhtml">
                <f:param name="from" value="BusEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
